package com.wisnews.util;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.wisnews.pojo.sr.entity.Member;

import javax.servlet.http.HttpServletRequest;
import java.util.Calendar;
import java.util.Date;

/**
 * @Description：
 * @Author: yuyd
 * @Email: yyd8358@foxmail.com
 * @Date: 2021/2/25 15:32
 * @Version 1.0
 */
public final class FileUploadUtil {

    /**
     * @description: 获取登录用户信息
     * @param:
     * @return:
     * @author yuyd
     * @date: 2021/5/4 21:32
     */
    public static   Member getLoginMemberInfo(HttpServletRequest request){

        Object member = request.getSession().getAttribute("member");
        Member user = null;
        if (ObjectUtils.isNotNull(member) && member instanceof Member){
            user = (Member)member;
        }
        return user;
    }

    /**
     * @description: 根据上传时间生成文件名
     * @param:
     * @return:
     * @author yuyd
     * @date: 2021/5/4 21:32
     */
    public static String generateRandomFileName(){
        String prefix = DateUtil.format(new Date(), "yyyyMMddHHmmss");
        long timeInMillis = Calendar.getInstance().getTimeInMillis();
        return prefix+"_"+timeInMillis;
    }

}
